#ifndef	PLANARMESH_H
#define	PLANARMESH_H

#include "vector3.h"

#include <iostream>
#include <stdlib.h>
#include <cstdlib>
#include <stdio.h>

using namespace std;

/*
	Builds a planar mesh suitable for use with OpenGL vector arrays.

	Perry Kivolowitz - University of Wisconsin CS 559
*/

class PlanarMesh
{
public:
	typedef struct
	{
		int V1;
		int V2;
		int V3;
	} TRIANGLE;

	enum WhichArray
	{
		InArray,
		OutArray
	};

	enum MeshStyle
	{
		Regular,
		Flexible
	};

	PlanarMesh(int xDensity, int yDensity, MeshStyle meshStyle = Regular);
	PlanarMesh();
	~PlanarMesh();
	void Draw(WhichArray whichArray = InArray, bool drawNormals = false);
	void ResizeMesh(int xDensity, int yDensity, MeshStyle meshStyle = Regular);
	void GetDensity(int & x, int & y);
	const char * BoundsString();
	void PrintVectorArray( Vector3 * ); // For testing
	void PrintTriangleArray( TRIANGLE * ); // For testing
	void AdjustOutArray(int, int);

	Vector3 * GetInArray();
	Vector3 * GetOutArray();
	Vector3 * GetInTextureCoordinates();
	Vector3 * GetOutTextureCoordinates();
	Vector3 * GetInNormals();
	Vector3 * GetOutNormals();
	TRIANGLE * GetTArray(); // For testing


private:
	Vector3		* VInArray;			// A pristine grid.
	Vector3		* VTInArray;		// The unchanging texture coordinate grid.
	Vector3		* VTOutArray;		// A changable texture coordinate array.
	Vector3		* VOutArray;		// A potentially modified grid.
	TRIANGLE	* TArray;			// An array defining the triangles in the grid.
	Vector3		* NInArray;			// A printing grid of NORMALS
	Vector3		* NOutArray;		// A potentially modified grid of NORMALS

	int xDensity;
	int yDensity;

	void MakeMesh(MeshStyle meshStyle);
	void ReleaseMemory();
	void AllocateMemory();

	char boundsBuffer[1024]; // Used with sprintf_s.
};

#endif
